﻿
$("#FDinput").watermark("请输入辅导名称或辅导班名称");
$("#PXinput").watermark("请输入培训名称或培训班名称");
$("#LSinput").watermark("请输入老师名称或者老师编号");
$("#JGinput").watermark("请输入机构名称或者机构编号");

$("#Contant").block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
$(".topNava >cite").bind("click", function () {
    //$(".strongcite").removeClass("strongcite");
    var id = $(this).attr("id");
    $(this).addClass("strongcite").siblings().removeClass("strongcite");
    $(".sear-form").hide();
    $("#" + id + "Div").fadeIn();
})
$("#SCBZA").click(function () {
    AddFavorite(window.location, document.title);
});
$("div.top>a").click(function () {

    switch ($(this).attr("id")) {
        //我的选课单 
        case "wdxkd":
            demoIframe[0].src = '';
            break;
        //我的消息   
        case "wdxx":
            demoIframe[0].src = 'Mess.aspx';
            break;
        //我的关注     
        case "wdgz":
            demoIframe[0].src = 'WSXY/MyFocus.aspx';
            break;
    }
})

$("#TZCDSXDIV").powerFloat({
    eventType: "click",
    target: $("#ChangNavaDiv"),
    position: "2-1"
});
$("#litNavaSort>select").live("change", function () {
    var SelectValue = $(this).val();
    var NextSpan = $(this).next();
    var index = NextSpan.attr("id").replace("DHSPAN", "");
    $(this).val(index);
    var ChangeToSpan = $("#DHSPAN" + SelectValue);
    var NextSpanText = NextSpan.text();
    NextSpan.text(ChangeToSpan.text());
    ChangeToSpan.text(NextSpanText);
});
$(".rootnava,.parentnava").toggle(function () {
    var next = $(this).next();

    next.fadeOut();
    $(this).children("img");
    $(this).children("img").attr("src", "/Scripts/jquery-easyui-1.3.1/themes/icons/edit_add.png");
}, function () {
    var next = $(this).next();

    next.fadeIn();
    $(this).children("img").attr("src", "/Scripts/jquery-easyui-1.3.1/themes/icons/edit_remove.png");
});

$("#CancelSortNava").click(function () {
    $.powerFloat.hide();
});

$("#QDSortNava").click(function () {
    $('.leftNava').block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    var LeftNavaString = new Array();
    $("#litNavaSort>span").each(function () {
        LeftNavaString.push($(this).attr("id").replace("DHSPAN", ""));
    });
    $.post("Default.aspx", { Operate: "ChangNava", Nava: LeftNavaString.join("_") }, function (ReturnMess) {
        if (ReturnMess == "success") {
            LoadTree();
        }
        else {
            $('.leftNava').unblock();
            alert(ReturnMess);
        }
    });
});
$("#AQTC").click(function () {
    $.post("../../CheckOut/Login.aspx", { Check: "LogOut" }, function (ReturnMess) {
        if (ReturnMess == "success") {
            alert("安全退出成功");
        }
        else {
            alert(ReturnMess);
        }
        window.location.href = '/';
    });

});

var CssClass = {
    classA: { "font-size": "13px", "font-weight": "normal", "color": "Gray" },
    classB: { "font-size": "13px", "color": "Grey" }
};
var zTree, demoIframe;
var setting = {
    view: {
        dblClickExpand: false,
        showLine: false,
        selectedMulti: false,
        fontCss: getFont,
        expandSpeed: ($.browser.msie && parseInt($.browser.version) <= 6) ? "" : "fast"
    },
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "pId",
            rootPId: ""
        }
    },
    callback: {
        beforeClick: function (treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("tree");
            if (treeNode.isParent) {
                zTree.expandNode(treeNode);
                return false;
            } else {
                demoIframe.attr("src", treeNode.link);
                return true;
            }
        }
    }
};

function LoadTree() {
    $('.leftNava').block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    $.ajax({
        dataType: "json",
        type: "get",
        url: "Default.aspx?Operate=GetNodes&r=" + Math.random(),
        success: function (data) {
            $('.leftNava').unblock();
            if (data == null) {
                alert("请重新登入！");
                return;
            }
            if (data.length > 0) {
                //构建树
                var t = $("#tree");
                t = $.fn.zTree.init(t, setting, data);
                demoIframe = $("#testIframe");
                demoIframe.bind("load", loadReady);
                zTree = $.fn.zTree.getZTreeObj("tree");
                //zTree.selectNode(zTree.getNodeByParam("id", 101));
                loadReady();
            }

        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            // 加载树发生异常
            alert("加载树发生异常！");
        }
    });

}

function LoadKJNava() {
    $("#ChangNavaDiv").block({ message: '<img alt="加载中" src="/images/Loading/Uploader.gif" />', css: { border: 'none', backgroundColor: 'transparent'} });
    $.ajax({
        type: "get",
        url: "Default.aspx?Operate=GetKeyNava&r=" + Math.random(),
        success: function (data) {
            $("#ChangNavaDiv").unblock();
            $("#litNavaSort").html(data);
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            // 加载树发生异常
            alert("加载树发生异常！");
        }
    });
}
function LoadTopNava() {
    if (demoIframe[0].src == "") {
        $.ajax({
            type: "get",
            url: "Default.aspx?Operate=GetHome&r=" + Math.random(),
            success: function (data) {

                $(".right1").removeClass("Active");
                $("#TopNava" + data).addClass("Active");
                switch (data) {
                    case "1":
                        demoIframe[0].src = 'WSXY/';
                        break;
                    case "2":
                        demoIframe[0].src = 'JXZX/';
                        break;
                    case "4":
                        demoIframe[0].src = 'Account/';
                        break;
                    default:
                        demoIframe[0].src = 'WSXY/';
                        break;

                }
                $("#Contant").unblock();
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                // 加载树发生异常
                $("#Contant").unblock();
                alert("加载树发生异常！");
            }
        });
    }
}

$(document).ready(function () {
    LoadTree();
    LoadKJNava();
});
function getFont(treeId, node) {
    return node.cssclass ? CssClass[node.cssclass] : {};
}

function loadReady() {
    LoadTopNava();
    var bodyH = demoIframe.contents().find("body").get(0).scrollHeight,
		htmlH = demoIframe.contents().find("html").get(0).scrollHeight,
		maxH = Math.max(bodyH, htmlH), minH = Math.min(bodyH, htmlH),
		h = demoIframe.height() >= maxH ? minH : maxH;
    if (h < 630) h = 630;
    demoIframe.height(h);

}
